<template>
  <div class="view-container" @keyup.enter="login(loginFormRef)">
    <div class="login-box">
      <el-form ref="loginFormRef" :model="loginForm.val" :rules="loginRules">
        <h3 class="title">油气集输站中心监控系统</h3>
        <el-form-item prop="username">
          <el-input
            v-model="loginForm.val.username"
            type="text"
            auto-complete="on"
            placeholder="账号"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.val.password"
            type="password"
            show-password
            placeholder="密码"
          ></el-input>
        </el-form-item>
        <div class="row">
          <div class="captcha">
            <img :src="captchaSrc" @click="refreshCode" />
          </div>
          <el-form-item prop="code">
            <el-input v-model="loginForm.val.code" type="text" placeholder="验证码"></el-input>
          </el-form-item>
        </div>
        <el-form-item>
          <el-button type="primary" :loading="logining" class="submit" @click="login(loginFormRef)"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
      <div class="find-password"><RouterLink :to="`/findPassword`">找回密码</RouterLink></div>
    </div>
  </div>
</template>

<script setup name="TestPage">
import { ref } from 'vue'
import { useUser } from '../hooks/useUser'
const loginFormRef = ref()
const { captchaSrc, loginRules, logining, loginForm, login, refreshCode } = useUser()
refreshCode()
</script>

<style lang="less" scoped>
.view-container {
  width: 100%;
  height: 100%;
  background: url('../assets/login-background.png') no-repeat center center;
  background-size: contain;
  display: flex;
  justify-content: center;
  align-items: center;
  .login-box {
    background: #fff;
    width: 350px;
    height: 280px;
    padding: 15px 35px 15px;
    box-shadow: 0 0 15px #cac6c6;
    -webkit-border-radius: 20px;
    border-radius: 20px;
    .submit {
      width: 100%;
    }
    .title {
      margin-bottom: 15px;
      font-family: Consolas;
      text-align: center;
    }
    .captcha {
      height: 40px;
      width: 120px;
    }
    .row {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .find-password {
      line-height: 12px;
      font-size: 12px;
      text-align: right;
      > a {
        color: #999;
        text-decoration: none;
      }
    }
  }
}
</style>
